package com.softeem.score.manager.controller.admin;


import com.github.pagehelper.PageInfo;
import com.softeem.score.common.log.annotation.Log;
import com.softeem.score.common.log.enums.OperatorType;
import com.softeem.score.manager.service.CollegeService;
import com.softeem.score.model.entity.CollegeEntity;
import com.softeem.score.model.entity.school.College;
import com.softeem.score.model.vo.common.Result;
import com.softeem.score.model.vo.common.ResultCodeEnum;
import com.softeem.score.model.vo.school.CollegeVo;
import com.softeem.score.model.vo.school.MajorVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhu
 * @since 2024-02-14
 */
@Tag(name = "学院管理")
@RestController
@RequestMapping("/admin/school/college")
public class CollegeController {
    @Autowired
    private CollegeService collegeService;

    @Operation(summary = "分页查询学院信息")
    @GetMapping(value = "/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<CollegeVo>> findByPage(@PathVariable(value = "pageNum") Integer pageNum,
                                                  @PathVariable(value = "pageSize") Integer pageSize,
                                                  MajorVo majorVo) {
        PageInfo<CollegeVo> collegeVoPageInfo = collegeService.findByPage(majorVo, pageNum, pageSize);
        return Result.build(collegeVoPageInfo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "查询所有学院信息")
    @GetMapping("/getAllCollege")
    public Result<List<CollegeEntity>> getAllCollege() {
        List<CollegeEntity> collegeList = collegeService.getAllCollege();
        return Result.build(collegeList, ResultCodeEnum.SUCCESS);
    }
    @Log(title = "保存学院信息",businessType = 1,operatorType = OperatorType.MANAGE)
    @Operation(summary = "保存学院信息")
    @PostMapping(value = "/saveCollege")
    public Result saveCollege(@RequestBody College college) {
        collegeService.saveCollege(college);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
    @Log(title = "更新学院信息",businessType = 2,operatorType = OperatorType.MANAGE)
    @Operation(summary = "更新学院信息")
    @PutMapping(value = "/updateCollege")
    public Result updateCollege(@RequestBody College college) {
        collegeService.updateCollege(college);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
    @Log(title = "删除学院信息",businessType = 3,operatorType = OperatorType.MANAGE)
    @Operation(summary = "删除学院信息")
    @DeleteMapping(value = "/deleteById/{collegeId}")
    public Result deleteById(@PathVariable(value = "collegeId") Long collegeId) {
        collegeService.deleteById(collegeId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
}

